import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app/view/community/handpick_page.dart';

import '../screen_page.dart';
import 'community/attention_page.dart';
import 'community/community_find_page.dart';

class Community extends StatefulWidget {
  @override
  _CommunityState createState() => _CommunityState();
}

class _CommunityState extends State<Community>
    with SingleTickerProviderStateMixin {
  TabController controller;
  int currentIndex = 0;

  @override
  void initState() {
    super.initState();
    controller = TabController(vsync: this, length: 6);
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.dark,
      child: Scaffold(
        appBar: PreferredSize(
            child: Container(
              width: double.infinity,
              height: double.infinity,
              decoration: BoxDecoration(
                color: Colors.white,
                //   gradient: LinearGradient(colors: [Colors.yellow, Colors.pink])
              ),
              child: _top(),
            ),
            preferredSize: Size(double.infinity, 40)),
        body: DefaultTabController(
            length: 6,
            child: Container(
              decoration: BoxDecoration(
                color: Color(0xFFF3F3F3),
              ),
              child: Column(
                children: <Widget>[
                  _bottom(),
                  //   _search(),
                ],
              ),
            )),
      ),
    );
  }

  //顶部
  Widget _top() {
    return SafeArea(
      child: Container(
        width: double.infinity,
        height: height(44),
        color: Colors.white,
        child: TabBar(
            controller: controller,
            unselectedLabelColor: Colors.black54,
            unselectedLabelStyle: TextStyle(fontSize: sp(12)),
            labelColor: Colors.pink,
            labelStyle: TextStyle(fontSize: sp(21)),
            indicatorColor: Colors.transparent,
            labelPadding: EdgeInsets.all(0),
            //文字显示不全这里设置成0，即代表不加padding
            indicatorSize: TabBarIndicatorSize.tab,
            tabs: tabs),
      ),
    );
  }

  final List<Widget> plazaList = [
    AttentionPage(),
    CommunityFindPage(),
    HandPickPage(),
    AttentionPage(),
    AttentionPage(),
    AttentionPage(),
  ];

  Widget _bottom() {
    return Expanded(
        flex: 1,
        child: TabBarView(controller: controller, children: plazaList));
  }

  List<Widget> tabs = [
    Text(
      "关注",
    ),
    Text(
      "发现",
    ),
    Text(
      "精选",
    ),
    Text(
      "酒评",
    ),
    Text(
      "问答",
    ),
    Text(
      "咨询",
    ),
  ];
}
